#include "widget.h"
#include "ui_widget.h"
#include <qaction.h>
#include <qmenu.h>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);
    _tray=new QSystemTrayIcon(this);
    connect(_tray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this,SLOT(onActiveTray(QSystemTrayIcon::ActivationReason)));
    _tray->setIcon(QIcon(":/w.png"));
    QAction *setting=new QAction(tr("setting"),this);
    connect(setting,SIGNAL(triggered(bool)),
            this,SLOT(onSetting()));
    QAction*close=new QAction(tr("close"),this);
    connect(close,SIGNAL(triggered(bool)),
            this,SLOT(onClose()));
    QMenu *menu=new QMenu;
    menu->addAction(setting);
    menu->addAction(close);
    _tray->setContextMenu(menu);
    _tray->show();
    _wallpaper=new fWallpaper;
    _wallpaper->show();
    connect(ui->pbClose,SIGNAL(clicked(bool)),this,SLOT(onHinde()));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::onSetting()
{
    this->show();
}
void Widget::onClose()
{
    _wallpaper->close();
    this->close();
}

void Widget::onHinde(){
    this->hide();
}
void Widget::onActiveTray(QSystemTrayIcon::ActivationReason reason)
{
    switch(reason)
    {
    case QSystemTrayIcon::Context:
    {
        _tray->contextMenu()->show();
    }break;
    case QSystemTrayIcon::DoubleClick:
    case QSystemTrayIcon::Trigger:
    {
        onSetting();
    }break;
    }
}
